<template>
  <a-drawer v-model:visible="visible" title="任务详情" :width="width >= 500 ? 500 : '100%'" :footer="false">
    <a-descriptions :column="2" size="large" class="general-description">
      <a-descriptions-item label="ID" :span="2">
        <a-typography-paragraph copyable>{{ dataDetail?.id }}</a-typography-paragraph>
      </a-descriptions-item>
      <a-descriptions-item label="任务名称" :span="2">{{ dataDetail?.title }}</a-descriptions-item>
      <a-descriptions-item label="触发类型" :span="2">
        <GiCellTag :value="dataDetail?.triggerType" :dict="job_trigger_type_enum" />
      </a-descriptions-item>
      <a-descriptions-item v-if="dataDetail?.triggerType === 2" label="Cron">{{ dataDetail?.cron }}</a-descriptions-item>
      <a-descriptions-item v-else-if="dataDetail?.triggerType === 1" label="间隔时长">{{ dataDetail?.fixedInterval }} 秒</a-descriptions-item>
      <a-descriptions-item label="执行器类名" :span="2">{{ dataDetail?.jobClassName }}</a-descriptions-item>
      <a-descriptions-item label="任务参数" :span="2">{{ dataDetail?.param }}</a-descriptions-item>
      <a-descriptions-item label="任务状态">
        <GiCellTag :value="dataDetail?.status" :dict="job_status_enum" />
      </a-descriptions-item>
      <a-descriptions-item label="描述" :span="2">{{ dataDetail?.description }}</a-descriptions-item>
    </a-descriptions>
  </a-drawer>
</template>

<script setup lang="ts">
import { useWindowSize } from '@vueuse/core'
import type { JobResp } from '@/apis/scheduler'
import { useDict } from '@/hooks/app'

const { width } = useWindowSize()

const dataDetail = ref<JobResp>()
const visible = ref(false)
const { job_status_enum, job_trigger_type_enum } = useDict(
  'job_status_enum',
  'job_trigger_type_enum'
)

// 打开
const onOpen = (record: JobResp) => {
  dataDetail.value = record
  visible.value = true
}

defineExpose({ onOpen })
</script>
